package tests.jdl.databaseObjects.sqlite;

import jdl.databaseObjects.DbType;
import jdl.databaseObjects.DbTypeUnknownException;
import jdl.databaseObjects.datatypes.sqlite.SqliteDbTypeFactory;
import jdl.databaseObjects.sqlite.datatypes.VarcharDbType;
import junit.framework.Assert;

import org.junit.Test;

public class SqliteDbTypeFactory_Test {
	@Test
	public void createIntDbType() {
		DbType firstType = SqliteDbTypeFactory.createIntDbType();
		DbType secondType = SqliteDbTypeFactory.createIntDbType();
		Assert.assertEquals(firstType, secondType);
		Assert.assertNotNull(firstType);
	}

	@Test
	public void createVarcharDbType() {
		DbType firstType = SqliteDbTypeFactory.createVarcharDbType(10);
		DbType secondType = SqliteDbTypeFactory.createVarcharDbType(10);
		Assert.assertEquals(firstType, secondType);
		Assert.assertNotNull(firstType);
	}

	@Test
	public void fromString_typeIsInteger() throws DbTypeUnknownException {
		DbType type = SqliteDbTypeFactory.fromString("iNtEgEr");
		Assert.assertEquals(SqliteDbTypeFactory.createIntegerDbType(), type);
	}

	@Test
	public void fromString_typeIsVarchar50() throws DbTypeUnknownException {
		DbType type = SqliteDbTypeFactory.fromString("varchar(50)");
		Assert.assertEquals(50, type.getSize());
		Assert.assertEquals(new VarcharDbType(50), type);
	}

	@Test
	public void fromString_typeIsBigint() throws DbTypeUnknownException {
		DbType type = SqliteDbTypeFactory.fromString("BiGiNt");
		Assert.assertEquals(SqliteDbTypeFactory.createBigintDbType(), type);
	}

	@Test(expected = DbTypeUnknownException.class)
	public void fromString_typeIsUnknown() throws DbTypeUnknownException {
		SqliteDbTypeFactory.fromString("qwerty");
	}

	@Test
	public void fromString_typeIsInt() throws DbTypeUnknownException {
		DbType type = SqliteDbTypeFactory.fromString("InT");
		Assert.assertEquals(SqliteDbTypeFactory.createIntDbType(), type);
	}
}
